class CulturalHeritage::CulturePointsController < ApplicationController
  # GET /cultural_heritage/culture_points
  # GET /cultural_heritage/culture_points.xml
  def index
    @cultural_heritage_culture_points = CulturalHeritage::CulturePoint.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @cultural_heritage_culture_points }
    end
  end

  # GET /cultural_heritage/culture_points/1
  # GET /cultural_heritage/culture_points/1.xml
  def show
    @cultural_heritage_culture = CulturalHeritage::Culture.find(params[:id])
    points = @cultural_heritage_culture.list_point

    if points.length > 0

      count = 0
      @json = "[["
      points.each do |point|
        if (count == 0)
          @json = @json << '{"lng": ' << point.longitude.to_s << ', "lat": ' << point.latitude.to_s << 
            ', "strokeColor": "#FF0000", "strokeOpacity": 0.3, "strokeWeight": 1, "fillColor": "#FF0000", "fillOpacity": 0.7}'
        else
          @json = @json << ', {"lng": ' << point.longitude.to_s << ', "lat": ' << point.latitude.to_s << '}'
        end
        count = count + 1
      end
      @json = @json << "]]"

    end 
    
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @cultural_heritage_culture_point }
    end
  end

  # GET /cultural_heritage/culture_points/new
  # GET /cultural_heritage/culture_points/new.xml
  def new
    @cultural_heritage_culture_point = CulturalHeritage::CulturePoint.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @cultural_heritage_culture_point }
    end
  end

  # GET /cultural_heritage/culture_points/1/edit
  def edit
    @cultural_heritage_culture_point = CulturalHeritage::CulturePoint.find(params[:id])
  end

  # POST /cultural_heritage/culture_points
  # POST /cultural_heritage/culture_points.xml
  def create
    @cultural_heritage_culture_point = CulturalHeritage::CulturePoint.new(params[:cultural_heritage_culture_point])

    respond_to do |format|
      if @cultural_heritage_culture_point.save
        format.html { redirect_to(@cultural_heritage_culture_point, :notice => 'Culture point was successfully created.') }
        format.xml  { render :xml => @cultural_heritage_culture_point, :status => :created, :location => @cultural_heritage_culture_point }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @cultural_heritage_culture_point.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /cultural_heritage/culture_points/1
  # PUT /cultural_heritage/culture_points/1.xml
  def update
    @cultural_heritage_culture_point = CulturalHeritage::CulturePoint.find(params[:id])

    respond_to do |format|
      if @cultural_heritage_culture_point.update_attributes(params[:cultural_heritage_culture_point])
        format.html { redirect_to(@cultural_heritage_culture_point, :notice => 'Culture point was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @cultural_heritage_culture_point.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /cultural_heritage/culture_points/1
  # DELETE /cultural_heritage/culture_points/1.xml
  def destroy
    @cultural_heritage_culture_point = CulturalHeritage::CulturePoint.find(params[:id])
    @cultural_heritage_culture_point.destroy

    respond_to do |format|
      format.html { redirect_to(cultural_heritage_culture_points_url) }
      format.xml  { head :ok }
    end
  end
end
